package generic;

import java.util.ArrayList;
import java.util.Comparator;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-02-27
 * Time:21:32
 */
@SuppressWarnings("all")
public class Exercise1 {
    public static void main(String[] args) {
        ArrayList<Employee> employees = new ArrayList<>();
        employees.add(new Employee("zhangsan", 2000.0, new MyDate(1993, 12, 6)));
        employees.add(new Employee("lisi", 2600.0, new MyDate(2000, 9, 28)));
        employees.add(new Employee("zhangsan", 4000.0, new MyDate(1993, 12, 2)));
        employees.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                String s1 = o1.getName();
                String s2 = o2.getName();
                if (s1.equals(s2)) {
                    MyDate d1 = o1.getBirthday();
                    MyDate d2 = o2.getBirthday();
                    return d1.compareTo(d2);
                } else {
                    return s1.compareTo(s2);
                }
            }
        });
        System.out.println(employees);
    }
}

@SuppressWarnings("all")
class Employee {
    private String name;
    private double sal;
    private MyDate birthday;

    public Employee(String name, double sal, MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "\nEmployee{" +
                "name='" + name + '\'' +
                ",\t sal=" + sal +
                ",\t birthday=" + birthday +
                '}';
    }
}

@SuppressWarnings("all")
class MyDate implements Comparable<MyDate> {
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }

    @Override
    public int compareTo(MyDate o) {
        if (o.year != this.year) {
            return this.year - o.year;
        } else if (o.month != this.month) {
            return this.month - o.month;
        } else {
            return this.day - o.day;
        }
    }
}
